<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="老师名字">
        <el-input v-model="queryParams.teacherName" placeholder="老师名字" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
              <el-button
                type="primary"
                plain
                icon="el-icon-plus"
                size="mini"
                @click="handleAdd"
                v-hasPermi="['system:role:add']"
                >新增</el-button
              >
            </el-col> -->
      <el-col :span="1.5">
        <!-- <el-button
                    type="success"
                    plain
                    icon="el-icon-edit"
                    size="mini"
                    :disabled="single"
                    @click="handleUpdate"
                    v-hasPermi="['system:role:edit']"
                    >修改</el-button
                  > -->
      </el-col>
      <el-col :span="1.5"> </el-col>
      <el-col v-if="user == 'admin'" :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
       >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table  v-loading="loading" @sort-change="paixu"
     :data="roleList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column width="150" sortable="custom" label="老师姓名" prop="teacherName" />
      <!-- <el-table-column width="150" sortable="custom" label="性别" prop="sex" />
      <el-table-column width="150" sortable="custom" label="年龄" prop="age" />
      <el-table-column width="150" sortable="custom" label="时差" prop="timeDifference" /> -->




      <!-- <el-table-column label="性别" prop="sex"> </el-table-column>

      <el-table-column label="年龄" prop="age" />
      <el-table-column label="时差" prop="timeDifference" /> -->
      <el-table-column width="150"  sortable="custom" label="总接单量" prop="totalCount" />
      <el-table-column width="150" sortable="custom" label="当年接单量" prop="yearCount" />
      <el-table-column width="150" sortable="custom" label="挂科率" prop="failRate" />
      <el-table-column width="150" sortable="custom" label="退款费率" prop="failRate">
        <template slot-scope="scope">
          {{
      ((scope.row.refundMoney / scope.row.amountMoney) * 100).toFixed(2) +
      "%"
    }}
        </template>
      </el-table-column>
      <el-table-column width="150" sortable="custom" label="客诉率" prop="amountMoney">
        <template slot-scope="scope">
          {{
        ((scope.row.complaintCount / scope.row.totalCount) * 100).toFixed(
          2
        ) + "%"
      }}
        </template>
      </el-table-column>
      <el-table-column width="150" sortable="custom" label="超时率1" prop="refundMoney">
        <template slot-scope="scope">
          {{
        (
          (scope.row.overtimeOne /
            (scope.row.overtimeOne +
              scope.row.overtimeTwo +
              scope.row.overtimeThree +
              scope.row.inTime)) *
          100
        ).toFixed(2) + "%"
      }}
        </template>
      </el-table-column>
      <el-table-column width="150" sortable="custom" label="超时率2" prop="refundMoney">
        <template slot-scope="scope">
          {{
        (
          (scope.row.overtimeTwo /
            (scope.row.overtimeOne +
              scope.row.overtimeTwo +
              scope.row.overtimeThree +
              scope.row.inTime)) *
          100
        ).toFixed(2) + "%"
      }}
        </template>
      </el-table-column>
      <el-table-column  sortable="custom" label="超时率3" width="100" prop="refundMoney">
        <template slot-scope="scope">
          {{
        (
          (scope.row.overtimeThree /
            (scope.row.overtimeOne +
              scope.row.overtimeTwo +
              scope.row.overtimeThree +
              scope.row.inTime)) *
          100
        ).toFixed(2) + "%"
      }}
        </template>
      </el-table-column>
      <el-table-column sortable="custom" label="及时交稿率" width="120" prop="refundMoney">
        <template slot-scope="scope">
          {{
        (
          (scope.row.inTime /
          scope.row.totalCount) *
          100
        ).toFixed(2) + "%"
      }}
        </template>
      </el-table-column>
      <el-table-column sortable="custom" label="保分达成率" width="120" prop="guarantee">

        <template slot-scope="scope">
          {{
       scope.row.guarantee
      }} %
        </template>
      </el-table-column>
      <el-table-column sortable="custom" label="再次选择（非常乐意）" width="200" prop="yesAgain">
      </el-table-column>
      <el-table-column sortable="custom" label="再次选择（坚决不）" width="200" prop="noAgain">
      </el-table-column>
      <el-table-column sortable="custom" label="平均客户下单数量" width="150" prop="average">


      </el-table-column>

      <el-table-column sortable="custom" label="复购率" width="100" prop="repurchaseRate">

        <template slot-scope="scope">
          {{
       scope.row.repurchaseRate
      }} %
        </template>
      </el-table-column>
      <el-table-column sortable="custom" label="1个月未下单尾单率" width="160" prop="oneMonthRate">
        <template slot-scope="scope">
          {{
       scope.row.oneMonthRate
      }} %
        </template>
      </el-table-column>
      <el-table-column sortable="custom" label="3个月未下单尾单率" width="160" prop="threeMonthRate">

        <template slot-scope="scope">
          {{
       scope.row.threeMonthRate
      }} %
        </template>
      </el-table-column>

      <!-- <el-table-column sortable="custom" label="建议及时性百分比" width="160" prop="suggest">
      </el-table-column> -->
      <el-table-column sortable="custom" label="能力评分（1-10）" width="160" prop="capacity">
      </el-table-column>

      <el-table-column sortable="custom" label="态度评分（1-10）" width="160" prop="manner">
      </el-table-column>

      <el-table-column sortable="custom" label="总评分" width="120">
        <template slot-scope="scope">
          {{ scope.row.capacity + scope.row.manner + scope.row.timeliness }}
        </template>
      </el-table-column>
      <el-table-column sortable="custom" label="容易出现的问题" width="160" prop="problem">
      </el-table-column>
      <el-table-column sortable="custom" label="辅导评分" width="120" prop="tutoringRating">
      </el-table-column>
      <el-table-column sortable="custom" label="辅导评价" width="120" prop="counselingEvaluation">
      </el-table-column>
      <el-table-column sortable="custom" label="小众专业度（1-10）" width="170" prop="minority">
      </el-table-column>

      <el-table-column sortable="custom" label="内容满意度" width="150" prop="contentSatisfaction">
      </el-table-column>

      <!-- <el-table-column sortable="custom" label="及时性满意度" width="150" prop="formatSatisfaction">
      </el-table-column>

      <el-table-column sortable="custom" label="实效满意度" width="120" prop="effectivenessSatisfaction">
      </el-table-column> -->
      <el-table-column sortable="custom" label="是否愿意再次找该老师" width="180" prop="agein">
      </el-table-column>

      <el-table-column sortable="custom" label="时差" prop="timeDifference">
      </el-table-column>

      <el-table-column sortable="custom" label="备注" prop="remark">
      </el-table-column>
      <el-table-column sortable="custom" label="即将达成的奖金比例" width="180" prop="bonusRatio">
      </el-table-column>
      <el-table-column sortable="custom" label="奖金差距条件" width="150" prop="bonusCondition">
      </el-table-column>
      <el-table-column label="结款周期" prop="settlementPeriod">
      </el-table-column>

      <el-table-column sortable="custom" label="写手加权综合评分" width="180" prop="comprehensiveEvaluation">
      </el-table-column>

      <el-table-column sortable="custom" label="写手加权综合排名" width="180" prop="integratedRanking">
      </el-table-column>

      <el-table-column sortable="custom" label="写手综合评分" width="150" prop="evaluation">
      </el-table-column>

    

      <el-table-column sortable="custom" label="写手综合排名" width="150" prop="ranking">
      </el-table-column>
      <el-table-column sortable="custom" label="内容满意度" width="150" prop="contentSatisfaction">
      </el-table-column>

      <!-- <el-table-column sortable="custom" label="及时性满意度" width="150" prop="formatSatisfaction">
      </el-table-column>

      <el-table-column sortable="custom" label="实效满意度" width="120" prop="effectivenessSatisfaction">
      </el-table-column> -->
      
      <el-table-column sortable="custom" label="服务满意度" width="150" prop="serviceSatisfaction">
      </el-table-column>
      <el-table-column sortable="custom" label="时效满意度" width="150" prop="prescriptionSatisfaction">
      </el-table-column>
      <el-table-column sortable="custom" label="是否愿意再次找该老师" width="180" prop="agein">
      </el-table-column>
      <el-table-column sortable="custom" label="总满意度" width="150" prop="sexualSatisfaction">
      </el-table-column>
   
      <el-table-column fixed="right" label="操作" align="center" width="200" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
           >修改</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <el-dialog @close="tuiqings" title="修改" :destroy-on-close="true" :close-on-click-modal="false"
      :visible.sync="chengjiloding">
      <el-form :model="teacherFrom" ref="fankuiluruform" label-width="180px" class="demo-ruleForm">
        <!-- @blur="bujiaformatAmount('premiumAmount')" -->
        <!-- <el-form-item label="能力评分">
          <el-input v-model="teacherFrom.capacity" placeholder="能力评分" />
        </el-form-item> -->

        <el-form-item label="能力评分">
          <el-input type="number" v-model="teacherFrom.capacity" placeholder="能力评分" />
        </el-form-item>
        <el-form-item label="态度评分">
          <el-input type="number" v-model="teacherFrom.manner" placeholder="态度评分" />
        </el-form-item>
        <el-form-item label="及时性评分">
          <el-input type="number" v-model="teacherFrom.timeliness" placeholder="及时性评分" />
        </el-form-item>
        <el-form-item label="容易出现的问题">
          <el-input v-model="teacherFrom.problem" placeholder="辅导评分" />
        </el-form-item>
        <el-form-item type="number" label="辅导评分">
          <el-input v-model="teacherFrom.tutoringRating" placeholder="辅导评分" />
        </el-form-item>
        <el-form-item label="辅导评价">
          <el-input v-model="teacherFrom.counselingEvaluation" placeholder="辅导评价" />
        </el-form-item>
        <el-form-item label="小众专业度（1-10）">
          <el-input type="number" v-model="teacherFrom.minority" placeholder="小众专业度（1-10）" />
        </el-form-item>
        <el-form-item label="内容满意度">
          <el-input v-model="teacherFrom.contentSatisfaction" placeholder="内容满意度" />
        </el-form-item>
        <el-form-item label="格式满意度">
          <el-input v-model="teacherFrom.formatSatisfaction" placeholder="及时性满意度" />
        </el-form-item>
        <el-form-item label="实效满意度">
          <el-input v-model="teacherFrom.effectivenessSatisfaction" placeholder="实效满意度" />
        </el-form-item>
        <el-form-item label="是否愿意再次找该老师">
          <el-select v-model="teacherFrom.agein" placeholder="" clearable style="width: 240px">
            <el-option v-for="dict in [
      { value: '是', label: '是' },
      { value: '否', label: '否' },
    ]" :key="dict.value" :label="dict.label" :value="dict.value" />
          </el-select>
        </el-form-item>


        <el-form-item label="即将达成的奖金比例">
          <el-input v-model="teacherFrom.bonusRatio" placeholder="即将达成的奖金比例" />
        </el-form-item>

        <el-form-item label="奖金差距条件">
          <el-input v-model="teacherFrom.bonusCondition" placeholder="奖金差距条件" />
        </el-form-item>

        <el-form-item label="结款周期">
          <el-input v-model="teacherFrom.settlementPeriod" placeholder="结款周期" />
        </el-form-item>
        <el-form-item label="写手加权综合评分">
          <el-input v-model="teacherFrom.comprehensiveEvaluation" placeholder="写手加权综合评分" />
        </el-form-item>

        <el-form-item label="写手加权综合排名">
          <el-input v-model="teacherFrom.integratedRanking" placeholder="写手加权综合排名" />
        </el-form-item>

        <el-form-item label="写手综合评分">
          <el-input v-model="teacherFrom.evaluation" placeholder="写手综合评分" />
        </el-form-item>

        <el-form-item label="写手综合排名">
          <el-input v-model="teacherFrom.ranking" placeholder="写手综合排名" />
        </el-form-item>

        <el-form-item label="备注">
          <el-input v-model="teacherFrom.remark" placeholder="备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button @click="chengjiloding = false">取 消</el-button>
        <el-button type="primary" @click="luruti">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listRole,
  getRole,
  delRole,
  addRole,
  updateRole,
  dataScope,
  changeRoleStatus,
  deptTreeSelect,
} from "@/api/system/role";
import { deleteixundan, paizneg } from "@/api/new";

import {
  listUser,
  duizhangon,
  keudi,
  laosdhiping,
  xiupingfen,
} from "../../api/new";
import {
  treeselect as menuTreeselect,
  roleMenuTreeselect,
} from "@/api/system/menu";

export default {
  name: "Role",
  dicts: ["sys_normal_disable"],
  data() {
    return {
      ketui: "",
      jiaojie: "",
      dai: "",
      // 遮罩层
      loading: true,
      // 选中数组
      xunkong: false,
      ids: [],
      xunkong: false,
      // 非单个禁用
      single: true,
      now: "",
      chengjiloding: false,
      hounow: 0,
      // 非多个禁用
      teacherFrom: {
        teacher_id: "",
        contentSatisfaction: "",
        formatSatisfaction: "",
        effectivenessSatisfaction: "",
        agein: "",
        bonusRatio: "",
        bonusCondition: "",
        settlementPeriod: "",
        comprehensiveEvaluation: "",
        integratedRanking: "",
        evaluation: "",
        ranking: "",
        remark: "",
        minority: '',
        counselingEvaluation: '',
        tutoringRating: '',
        problem: '',
        timeliness: '',
        manner: '',
        capacity: ''
      },
      kesuwanfromre: {
        workDate: [
          { required: true, message: "日期不能为空", trigger: "blur" },
        ],
        workOne: [{ required: true, message: "员工不能为空", trigger: "blur" }],
        workTwo: [{ required: true, message: "员工不能为空", trigger: "blur" }],
        restWorker: [
          { required: true, message: "员工不能为空", trigger: "blur" },
        ],
      },
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      roleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      user: this.$store.state.user.name,
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      // 日期范围
      dateRange: [],
      // 数据范围选项

      yiwei: [
        {
          value: "已成单",
          label: "已成单",
        },
        {
          value: "未成单",
          label: "未成单",
        },
      ],
      // 菜单列表
      menuOptions: [],
      // 部门列表
      deptOptions: [],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        teacherName: "",
        sortField: "",
        orderingRule: "",
      },
      chengdan: [],
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label",
      },
      // 表单校验
      rules: {
        roleName: [
          { required: true, message: "角色名称不能为空", trigger: "blur" },
        ],
        roleKey: [
          { required: true, message: "权限字符不能为空", trigger: "blur" },
        ],
        roleSort: [
          { required: true, message: "角色顺序不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },

  methods: {
    paixu(e, d) {
      let xu = "";
      if (e.order == "descending") xu = "desc";
      if (e.order == "ascending") xu = "asc";
      let a = e.prop.replace(/([A-Z])/g, "_$1").toLowerCase();

      this.queryParams.sortField = a;
      this.queryParams.orderingRule = xu;
      this.getList();
    },
    xundan() {
      this.$refs["xundanfrom"].validate((valid) => {
        if (valid) {
          if (this.title !== "添加") {
            paizneg([this.kesuwanfrom]).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.xunkong = false;
              this.getList();
            });
          } else {
            paizneg([this.kesuwanfrom]).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.xunkong = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      laosdhiping(this.queryParams).then((response) => {
        this.roleList = response.rows;
        // this.total = response.total;
        this.loading = false;
      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮（数据权限）
    cancelDataScope() {
      this.openDataScope = false;
      this.reset();
    },
    // 表单重置
    reset() {
      if (this.$refs.menu != undefined) {
        this.$refs.menu.setCheckedKeys([]);
      }
      (this.menuExpand = false),
        (this.menuNodeAll = false),
        (this.deptExpand = true),
        (this.deptNodeAll = false),
        (this.form = {
          complaintId: undefined,
          roleName: undefined,
          roleKey: undefined,
          roleSort: 0,
          status: "0",
          menuIds: [],
          deptIds: [],
          menuCheckStrictly: true,
          deptCheckStrictly: true,
          remark: undefined,
        });
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.teacherName = "";
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.followId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case "handleDataScope":
          this.handleDataScope(row);
          break;
        case "handleAuthUser":
          this.handleAuthUser(row);
          break;
        default:
          break;
      }
    },
    // 树权限（展开/折叠）

    guanbishoukan() {
      this.kesuwanfrom = {
        recordId: "",
        workDate: this.timestampToDateString(+new Date()),
        workOne: "",
        workTwo: "",
        restWorker: "",
      };
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.kesuwanfrom.workDate = this.timestampToDateString(+new Date());
      this.xunkong = true;
      this.title = "添加";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.chengjiloding = true;

      console.log(row);
      this.teacherFrom = row
      this.teacherFrom.teacherId = row.teacherId;
      this.teacherFrom.contentSatisfaction = row.contentSatisfaction;
      this.teacherFrom.formatSatisfaction = row.formatSatisfaction;
      this.teacherFrom.effectivenessSatisfaction =
        row.effectivenessSatisfaction;

      this.teacherFrom.agein = row.agein;
      this.teacherFrom.bonusRatio = row.bonusRatio;
      this.teacherFrom.bonusCondition = row.bonusCondition;
      this.teacherFrom.settlementPeriod = row.settlementPeriod;
      this.teacherFrom.comprehensiveEvaluation = row.comprehensiveEvaluation;
      this.teacherFrom.integratedRanking = row.integratedRanking;
      this.teacherFrom.evaluation = row.evaluation;
      this.teacherFrom.ranking = row.ranking;
      this.teacherFrom.remark = row.remark;
    },
    luruti() {
      xiupingfen(this.teacherFrom).then((result) => {
        this.getList();
        this.chengjiloding = false;
        this.$modal.msgSuccess("处理成功");
      });
    },

    tuiqings() {
      this.teacherFrom = {};
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.complaintId != undefined) {
            this.form.menuIds = this.getMenuAllCheckedKeys();
            updateRole(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            this.form.menuIds = this.getMenuAllCheckedKeys();
            addRole(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 提交按钮（数据权限） */
    submitDataScope: function () {
      if (this.form.complaintId != undefined) {
        this.form.deptIds = this.getDeptAllCheckedKeys();
        dataScope(this.form).then((response) => {
          this.$modal.msgSuccess("修改成功");
          this.openDataScope = false;
          this.getList();
        });
      }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const roleIds = row.followId || this.ids;
      this.$modal
        .confirm("是否确认删除数据项？")
        .then(function () {
          console.log(roleIds);
          return deleteixundan(roleIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "/system/score/export",
        {
          ...this.queryParams,
        },
        `老师评分${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>

